const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        navIndex: 0,
        curpage: 1,
        hasmore: true,
        page: 10,
        moreDetail: 'show',
        is_commander: 1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var self = this;
        if (options.commander == '1') {
            self.setData({
                is_commander: 1
            })
        }
        wx.getStorage({
            key: 'key',
            success: function (res) {
                self.setData({
                    key: res.data
                })
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        var self = this;
        wx.request({
            url: app.globalData.ApiUrl + '/index.php?act=wx_share&op=member_share',
            data: {
                key: self.data.key,
                is_commander: self.data.is_commander
            },
            method: 'POST',
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            success: res => {
                if (res.data.code == 200) {
                    self.setData({
                        share_info: res.data.datas
                    })
                }
            }
        })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },
    showMoreDetail: function (e) {
        var statu = e.currentTarget.dataset.statu;
        this.setData({
            moreDetail: statu
        })
    },
    shareRule: function () {
        wx.navigateTo({
            url: '../member_share_rule/member_share_rule'
        })
    },
    shareRank: function () {
        wx.navigateTo({
            url: '../member_share_rank/member_share_rank'
        })
    },
    getCash: function (e) {
        var self = this;
        var balance = e.currentTarget.dataset.balance;
        var minbalance = e.currentTarget.dataset.minbalance;
        if (balance - minbalance < 0) {
            wx.showToast({
                title: '可提现的最小金额为' + minbalance + '元',
                icon: 'none'
            })
            return false;
        }
        wx.showModal({
            title: '确认要提现',
            content: '奖励金额将被提现到个人充值卡中，每次提现金额为' + self.data.share_info.share_minto_predeposit + '元',
            success: res => {
                if (res.confirm) {
                    wx.request({
                        url: app.globalData.ApiUrl + '/index.php?act=wx_share&op=share_cash',
                        data: {
                            key: self.data.key,
                            balance: balance
                        },
                        method: 'POST',
                        header: {
                            'content-type': 'application/x-www-form-urlencoded'
                        },
                        success: res => {
                            if (res.data.code == 200) {
                                wx.showToast({
                                    title: res.data.datas,
                                    icon: 'none',
                                    success: () => {
                                        setTimeout(function () {
                                            wx.redirectTo({
                                                url: '../property_card/card'
                                            })
                                        }, 1500)
                                    }
                                })
                            } else {
                                wx.showToast({
                                    title: res.data.datas.error,
                                    icon: 'none'
                                })
                            }
                        }
                    })
                }
            }
        })
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})